	function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i = 0; i < arrCookie.length; i++){
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]){
            return arr[1];
        }
    }
    return "";
}
var page = 0;
var offset = 0;
var pageSize = 5;
var j=5;

var userid=getCookie("userid");



	function fenyecha(){
		taiocha();
		$.ajax({
			url:"http://localhost:16111/orderform/fenyecha",
			mimeType: "post",
			dataType: "json",
			data:{
				q:0,
				j:j,
				userid:userid
			},
			xhrFields:{withCredentials: true},
			success:function(date){
			
				var str="";
				console.log(date);
				for(i in date){
					var time=new Date(date[i].undertime);
					var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
				str+="<tr class='order-item'>"+
					"<td>"+
						"<label>"+
							"<a href='udai_order_detail.html' class='num'>"+ time2 +"订单号:" +date[i].ordernumber +"</a>"+
							"<div class='card'>"+
								"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
								"<div class='name ep2'>" +date[i].comitydescription + "</div>"+
								"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+
								"<div class='favour'>使用"+date[i].preferentialinformation + "</div>"+
							"</div>"+
						"</label>"+
					"</td>"+
					"<td>￥"+date[i].comityprices + "</td>"+
					"<td>"+date[i].comitynumber + "</td>"+
					"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
					"<td class='state'>"+
						"<a class='but c6'>" +date[i].orderstatus + "</a>"+
						"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
						
					"</td>"+
					"<td class='order'>"+
						"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
						"<a  class='but but-primary' onclick=ljfk(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\",\"" + date[i].spid + "\",\"" + date[i].specifications + "\",\"" + date[i].comityprices + "\",\"" + date[i].comitynumber + "\",\"" + date[i].comitypicture + "\")>"+date[i].statusbutton+"</a>"+
						"<a  class='but c3' onclick='tan("+ date[i].orderid +")'>取消订单</a>"+
					"</td>"+
				"</tr>";
				}
				
				document.getElementById("paymentcha").innerHTML = str;
			},
			
		});
	}
	
		function taiocha(){
			$.ajax({
			url: "http://localhost:16111/orderform/taiocha",
			mimeType: "post",
			dataType: "json",
			data:{
				
				userid:userid
			},
			xhrFields:{withCredentials: true},
			success: function(data){
				document.getElementById("article").innerHTML = data;
			},
			});
		}
		
		
			
	
		function san(){
			if(offset-pageSize<0){
						alert("没有上一页");
						return;
					}else{
						offset=offset-pageSize;
						page=page+1;
					} 
			var str="";
			$.ajax({
				url: "http://localhost:16111/orderform/fenyecha",
				mimeType: "post",
				dataType: "json",
				data:{
					q:offset,
					j:j,
					userid:userid
				},
				xhrFields:{withCredentials: true},
				success:function(date){
					var str="";
					console.log(date);
					for(i in date){
						var time=new Date(date[i].undertime);
						var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
						
					str+="<tr class='order-item'>"+
						"<td>"+
							"<label>"+
								"<a href='udai_order_detail.html' class='num'>"+ time2 +"订单号:" +date[i].ordernumber +"</a>"+
								"<div class='card'>"+
									"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
									"<div class='name ep2'>" +date[i].comitydescription + "</div>"+
									"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+
									"<div class='favour'>使用"+date[i].preferentialinformation + "</div>"+
								"</div>"+
							"</label>"+
						"</td>"+
						"<td>￥"+date[i].comityprices + "</td>"+
						"<td>"+date[i].comitynumber + "</td>"+
						"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
						"<td class='state'>"+
							"<a class='but c6'>" +date[i].orderstatus + "</a>"+
							"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
							
						"</td>"+
						"<td class='order'>"+
							"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
							"<a  class='but but-primary' onclick=ljfk(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\",\"" + date[i].spid + "\",\"" + date[i].specifications + "\",\"" + date[i].comityprices + "\",\"" + date[i].comitynumber + "\",\"" + date[i].comitypicture + "\")>"+date[i].statusbutton+"</a>"+
							"<a href='' class='but c3'>取消订单</a>"+
						"</td>"+
					"</tr>";
					}
					document.getElementById("paymentcha").innerHTML = str;
				},
				
			})
		}
		
		
		function xiao(){
			if(page==2){
							alert("没有下一页");
							return;
						}else{
							offset=offset+pageSize;
							page=page-1;
						} 
			$.ajax({
				url: "http://localhost:16111/orderform/fenyecha",
				mimeType: "post",
				dataType: "json",
				data:{
					q:offset,
					j:j,
					userid:userid
				},
				xhrFields:{withCredentials: true},
				success:function(date){
					
					var str="";
					for(i in date){
						var time=new Date(date[i].undertime);
					var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
					str+="<tr class='order-item'>"+
						"<td>"+
							"<label>"+
								"<a href='udai_order_detail.html' class='num'>"+ time2 +"订单号:" +date[i].ordernumber +"</a>"+
								"<div class='card'>"+
									"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
									"<div class='name ep2'>" +date[i].comitydescription + "</div>"+
									"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+
									"<div class='favour'>使用"+date[i].preferentialinformation + "</div>"+
								"</div>"+
							"</label>"+
						"</td>"+
						"<td>￥"+date[i].comityprices + "</td>"+
						"<td>"+date[i].comitynumber + "</td>"+
						"<td>￥"+date[i].actualpayment + "<br><span class='fz12 c6 text-nowrap'>(含运费: ¥" +date[i].freight + ")</span></td>"+
						"<td class='state'>"+
							"<a class='but c6'>" +date[i].orderstatus + "</a>"+
							"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情</a>"+
							
						"</td>"+
						"<td class='order'>"+
							"<div class='del'><span class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
							"<a  class='but but-primary' onclick=ljfk(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\",\"" + date[i].spid + "\",\"" + date[i].specifications + "\",\"" + date[i].comityprices + "\",\"" + date[i].comitynumber + "\",\"" + date[i].comitypicture + "\")>"+date[i].statusbutton+"</a>"+
							"<a href='' class='but c3'>取消订单</a>"+
						"</td>"+
					"</tr>";
					}
					document.getElementById("paymentcha").innerHTML = str;
				},
				
			})
		}
		
		
		
			
			function tan(orderid){
				
				localStorage.setItem("orderid",orderid);
				layui.use('layer', function() {
								var layer = layui.layer;
								layer.open({
									type: 2,
									title: '取消订单',
									fix: false,
									shadeClose: true,
									shade: 0.5,
									area: ['400px', '300px'],
									content: 'dcs.html',
									end: function() {
										
									}
								});
							});
						}
						
						
						paymentqx=function(){
													// var tr=$(x).closest("tr");
													// var coll =tr.find("td:eq(0)").text();
													// var xxx=coll.substring(23,32);
													var arr =localStorage.getItem("orderid");
													var reason=document.getElementById("reason").value;
													$.ajax({
														url: "http://localhost:16111/orderform/qx",
														mimeType: "post",
														dataType: "json",
														data:{orderid:arr,
														      cancel:reason},
														      xhrFields:{withCredentials: true},
														success:function(date){
															alert("取消成功")
															var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
																			parent.layer.close(index);//关闭窗口
																			parent.location.reload();//刷新顶层窗口
														},
														
													});
												}
						

function ljfk(t,orderid,ordernumber,spid,specifications,comityprices,comitynumber,comitypicture){
	$.ajax({
		type:"post",
		url:"http://localhost:16111/orderform/chams",
		data:{
			orderid:orderid
		},
		dateType:"json",
		 xhrFields:{withCredentials: true},
		success:function(date){
			
			var str = date;
	   		var arr = str.trim().split(" ");
	
 
	sessionStorage.setItem("orderid",orderid);
	window.location.href="udai_shopcart_pay.html?quantity="+comitynumber+"&commodity_picture="+comitypicture+"&commodity_nametop="+escape(arr[0])+"&commodity_description="+escape(arr[1])+"&shoppricezhekou="+comityprices+"&leixin="+escape(specifications)+"&status="+ordernumber;
	
	window.location.href="udai_shopcart_pay.html?quantity="+comitynumber+"&commodity_picture="+comitypicture+"&commodity_nametop="+escape(arr[0])+"&shoppricezhekou="+comityprices+"&leixin="+escape(leixin)+"&commodity_description="+escape(specifications)+"&id="+id+"&status="+ordernumber
		}
	});
}